﻿package app.view.components.guiDima.switchContent 
{
	import app.view.events.UIEvent;
	import com.snzflash.components.list.ListItemRenderer;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	/**
	 * ...
	 * @author Dmitryi_Koruagin, icq:585466579, dmitryikoruagin@yandex.ru
	 */
	public class PersonaItemDBase extends ListItemRenderer
	{
		// app.view.components.guiDima.switchContent.PersonaItemDBase
		
		//	public
		
		//	private
		public var text:TextField;
		//	const
		public static const WIDTH:Number = 205;
		public static const HEIGHT:Number = 114;
		
		public static const GAP_V:Number = 25;
		public static const GAP_H:Number = 25;
		//	CONSTRUCTOR
		public function PersonaItemDBase() 
		{
			super();
		}
		
		override protected function init():void
		{
			super.init();
			//trace('+++');
			
			text.mouseEnabled = false;
			text.wordWrap = true;
			text.multiline = true;
		};
		
		private function setEvents():void
		{
			doubleClickEnabled = true;
			//addEventListener(MouseEvent.ROLL_OVER, onItemOver);
			//addEventListener(MouseEvent.ROLL_OUT, onItemOut);
			addEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function removeEvents():void
		{
			//removeEventListener(MouseEvent.ROLL_OVER, onItemOver);
			//removeEventListener(MouseEvent.ROLL_OUT, onItemOut);
			removeEventListener(MouseEvent.CLICK, onClick);
		}
		
		override public function destroy():void 
		{
			super.destroy();
			
			removeEvents();
			
			
		};
		
		override public function get data():Object { return super.data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			//trace('data', data);
			
			text.text = _data.data.name;
			text.autoSize = TextFieldAutoSize.LEFT;
			
			text.x = WIDTH / 2 - text.width / 2;
			text.y = HEIGHT / 2 - text.height / 2;
			
			selected = false;
		};
		
		override public function get selected():Boolean { return _selected; };
		
		override public function set selected(value:Boolean):void 
		{
			_selected = value;
			
			/*if (_selected==true) 
			{
				removeEvents();
				buttonMode = useHandCursor = false;
			}else
			{
				setEvents();
				buttonMode = useHandCursor = true;
			}*/
			
			setEvents();
			buttonMode = useHandCursor = true;
		};
		
		private function onClick(e:MouseEvent):void 
		{
			//trace('on_Click');
			
			var ev:UIEvent = new UIEvent(UIEvent.CLICK_ITEM_EVENT);
			ev.data = data;
			dispatchEvent(ev);
			
		}
	}

}